<template>
	<view>
		<view class="set-password-he">
		  <h1>设置密码</h1>
		  <p>8-20个字符,不可以是纯数字</p>
		</view>
		<view class="set-password-input">
			<input-box
			style="background-color: #FFFFFF;"
			v-model="form.password" 
			ref="input2" 
			type="password"
			:verification="['isNull','isChineseEnlishAndNumber']" 
			:verificationTip="['密码不能为空','']" 
			placeholder="请输入密码" 
			maBtm="10"></input-box>
			<view style="margin: 16px;">
			  <van-button round block type="info" native-type="submit" @click="regiter">
				完成
			  </van-button>
			</view>
		</view>
	</view>
</template>

<script>
	
	import local from '@/utils/localStorage.js';
	
	export default {
		data() {
			return {
				pattern: /^[a-zA-Z]\w{5,17}$/,
				form:{
					loginName:undefined,
					password:undefined,
				}
			}
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			this.form.loginName = option.loginName;
			console.log("option.loginName:"+option.loginName);
		},
		methods: {
			async regiter(){
				if(this.$refs.input2.getValue()){
					// 添加用户信息
					const res = await this.$myRequest({
						url: '/api/login/addCustomer',
						method: 'post',
						data: this.form,
					});
					if(res.data.code == 200){
						uni.showToast({
							icon:"none",
							title: "登陆成功"
						})
						// 存储token
					    local.set("token",res.data.token);
						// 跳转到首页
						uni.switchTab({
							url:'/pages/index/index',
						})
					}else{
						uni.showToast({
							icon:"none",
							title: "错误,请联系开发人员"
						})
					}
				}
			}
		}
	}
</script>

<style>
.set-password-he h1{
    font-size: 1.5rem;
    padding: 1rem;
    text-align: left;
    margin-top: 30%;
  }
  .set-password-he p{
    font-size: 0.6rem;
    padding: 0 1rem;
    color: #999999;
  }
  .set-password-input{
    padding: 1rem;
  }
  .set-password-input .input{
    border-left: 1px solid #ccc;
    background-color: #ebedf0;
    margin: 0.8rem 0;
  }
</style>
